#include "QuickSort.h"
using namespace std;
QuickSort::QuickSort(long v[], long n)
{
    for (long i = 0; i < n; ++i)
        this -> array[i] = v[i];
}
void QuickSort::sort(long n)
{
    this -> Sort_quick(0, n - 1);
}
double QuickSort::getExecutionTime(long n)
{
    clock_t start, end;
    start = clock();
    this -> sort(n);
    end = clock();
    return (double)(end - start) / CLOCKS_PER_SEC;
}
void QuickSort::Sort_quick(long ll, long rl)
{
	long q;
	if (ll < rl)
	{
		q = Partition(ll, rl);
		Sort_quick(ll, q);
		Sort_quick(q + 1, rl);
    }
}
long QuickSort::Partition(long ll, long rl)
{
	long i = ll - 1;
	long j = rl + 1;
	long temp, aux = this -> array[ll];
    while (i < j)
	{
		++i;
        while (this -> array[i] < aux)
			++i;
		--j;
		while (this -> array[j] > aux)
			--j;
		if (i < j)
        {
			temp = this -> array[i];
			this -> array[i] = this -> array[j];
            this -> array[j] = temp;
		}
	}
    return j;
}
bool QuickSort::Check(long n)
{
	long i;
	bool  ok = true;
	for (i = 0; i < n - 1; ++i)
		if (this -> array[i] > this -> array[i + 1])
		{
			ok = false;
			break;
		}
	cout << "\t" << i;
	return ok;
}

